Create a LIFO QueueΒΆ

Q = queue.LifoQueue()

Create a LIFO Queue.
Expected output:
3 2 1 0
import queue

Q = queue.LifoQueue()

# insert items at the head of the queue
for i in range(4):
    Q.put(str(i))

# remove items from the head of the queue
while not Q.empty():
    print(Q.get(), end=" ")

Output:

3 2 1 0